package com.example.basic.excels;

import com.google.gson.Gson;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

public class Test {

    /**
     * 目标 解析xlsx文件（Excel）
     * 取出数据与已存在的数据进行对比。然后将已有的值拿到赋予
     * 最后生成 目标Json字符串
     */


    private static final int COLUMN_SIZE = 7;
    private static final int ROW_SIZE = 391;

    private static int entryId = 0;

    private static String[] months = new String[]{"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};

//    public static void main(String[] args) {
//
//        ArrayList<String> monthss = new ArrayList<>();
//        for (String month : months) {
//            monthss.add(month);
//        }
//
//        Workbook wb = null;
//        Sheet sheet = null;
//        Row row = null;
//        String cellData;
//        String filePath = "./source2.xlsx";
//        wb = ExcelReader.readExcel(filePath);
//
//
//        System.out.println("-------------------------解析Excel---------------------------");
//
//        if (wb != null) {
//            //用来存放表中数据
//            //拿到第一个
//            sheet = wb.getSheetAt(0);
//
//            for (int i = 0; i < ROW_SIZE; i++) {
//                row = sheet.getRow(i);
//                if (row != null) {
//
//
//                    for (int j = 0; j < COLUMN_SIZE; j++) {
//                        cellData = (String) ExcelReader.getCellFormatValue(row.getCell(j));
//
//                        if (cellData.contains(":")) {
//                            System.out.println(cellData);
//                            String[] split = cellData.split(":");
//                            int hour = Integer.parseInt(split[0]);
//                            int min = Integer.parseInt(split[1]);
//                            String number = (hour*60 + min) + "";
//                            row.getCell(j).setCellValue(number);
//                        }
//
//                    }
//                }
//            }
//        }
//
//        OutputStream outputStream = null;
//        try {
//            outputStream = new FileOutputStream("result2.xlsx");
//            wb.write(outputStream);
//        } catch (Exception e) {
//
//        } finally {
//            try {
//                if (outputStream != null) {
//                    outputStream.flush();
//                    outputStream.close();
//                }
//            } catch (Exception e) {
//
//            }
//            try{
//                if(wb != null){
//                    wb.close();
//                }
//            } catch (Exception e){
//
//            }
//        }
//    }

    public static void main(String[] args) {

        ArrayList<String> monthss = new ArrayList<>();
        for (String month : months) {
            monthss.add(month);
        }

        Workbook wb = null;
        Sheet sheet = null;
        Row row = null;
        ArrayList<Entry> list = null;
        String cellData = null;
//        String filePath = "./source.xlsx";
        String filePath = "./source2.xlsx";
        wb = ExcelReader.readExcel(filePath);

        String name = "";

        System.out.println("-------------------------解析Excel---------------------------");

        if (wb != null) {
            //用来存放表中数据
            //拿到第一个
            sheet = wb.getSheetAt(0);

            int weight = 1;

            HashMap<String, String[]> hashMap = new HashMap<>();
            ArrayList<String[]> cpp = new ArrayList<>();

            int currentMonth = 0;

            for (int i = 0; i < ROW_SIZE; i++) {

                String key = "";
                String[] value = new String[6];
                row = sheet.getRow(i);

                if (row != null) {

                    for (int j = 0; j < COLUMN_SIZE; j++) {
                        cellData = (String) ExcelReader.getCellFormatValue(row.getCell(j));

                        if (monthss.contains(cellData)) {
                            currentMonth = monthss.indexOf(cellData) + 1;
                            System.out.println("切换月份  " + currentMonth);
                            break;
                        }

                        if ("Date".equals(cellData)) {
                            System.out.println("标题数据,跳过读取");
                            break;
                        }

                        if ("".equals(cellData)) {
                            System.out.println("空数据,跳过读取");
                            break;
                        }

                        if (j == 0) {
                            System.out.print(currentMonth + "-" + cellData);
                        } else {
                            System.out.print(cellData);
                        }
                        System.out.print("   ");

                        if (j == 0) {
                            key = currentMonth + "-" + cellData;
                        } else {
                            if (cellData.length() != 5) {
                                throw new IllegalArgumentException("检测到表格数据中有不正常数据 对应日期为：" + key);
                            }

                            if (!cellData.contains(":")) {
                                throw new IllegalArgumentException("检测到表格数据中有不正常数据 对应日期为：" + key);
                            }

                            String[] split = cellData.split(":");
                            try {
                                int hour = Integer.parseInt(split[0]);
                                if (hour < 0 || hour >= 24) {
                                    throw new IllegalArgumentException("检测到表格数据中有不正常数据 对应日期为：" + key);
                                }
                                int min = Integer.parseInt(split[1]);
                                if (min < 0 || min >= 60) {
                                    throw new IllegalArgumentException("检测到表格数据中有不正常数据 对应日期为：" + key);
                                }
                            } catch (Exception e) {
                                throw new IllegalArgumentException("检测到表格数据中有不正常数据 对应日期为：" + key);
                            }

                            value[j - 1] = cellData;
                        }
                    }
                }

                if (!"".equals(key)) {
                    hashMap.put(key, value);
                    cpp.add(value);
                }
                System.out.println("\n--------------------------------------------------------------------------");
            }

            writeToFile(new Gson().toJson(hashMap));
            writeToCpp(new Gson().toJson(cpp));
            writeToBaoCpp(hashMap);

        }


    }

    private static void writeToBaoCpp(HashMap<String, String[]> source) {
        ArrayList<String[]> cpp = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            for (int i1 = 1; i1 <= 31; i1++) {
                String key = i + "-" + i1;
                String[] values = source.get(key);
                System.out.println("key = " + key + " value = " + values);
                if (values != null) {
                    cpp.add(new String[]{trans(values[0]),trans(values[1]),trans(values[2]),trans(values[3]),trans(values[4]),trans(values[4]),trans(values[5])});
                } else {
                    cpp.add(new String[]{"0","0","0","0","0","0","0"});
                }
            }
        }


        String toJson = new Gson().toJson(cpp);

        String regex1 = "\\[";
        String regex2 = "\\]";

        toJson = toJson.replaceAll(regex1,"{");
        toJson = toJson.replaceAll(regex2,"}");

        try {
//            File file = new File("./cTarget.json");
            File file = new File("./cBaoTarget2.json");
            System.out.println(file.exists());
            if (!file.exists()) {
                file.createNewFile();
            }

            BufferedWriter writer = new BufferedWriter(new FileWriter(file));
            writer.write(toJson);
            writer.flush();
            writer.close();
            System.out.println("文件写入完成");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private static String trans(String time) {
        String[] split = time.split(":");
        int hour = Integer.parseInt(split[0]);
        int min = Integer.parseInt(split[1]);
        return (hour*60 + min) + "";
    }

    private static void writeToCpp(String toJson) {

        String regex1 = "\\[";
        String regex2 = "\\]";

        toJson = toJson.replaceAll(regex1,"{");
        toJson = toJson.replaceAll(regex2,"}");

        try {
//            File file = new File("./cTarget.json");
            File file = new File("./cTarget2.json");
            System.out.println(file.exists());
            if (!file.exists()) {
                file.createNewFile();
            }

            BufferedWriter writer = new BufferedWriter(new FileWriter(file));
            writer.write(toJson);
            writer.flush();
            writer.close();
            System.out.println("文件写入完成");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void writeToFile(String toJson) {
        System.out.println("toJson = \n" + toJson);
        try {
//            File file = new File("./target.json");
            File file = new File("./target2.json");
            System.out.println(file.exists());
            if (!file.exists()) {
                file.createNewFile();
            }

            BufferedWriter writer = new BufferedWriter(new FileWriter(file));
            writer.write(toJson);
            writer.flush();
            writer.close();
            System.out.println("文件写入完成");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

//    public static void main(String[] args) {
//        Workbook wb =null;
//        Sheet sheet = null;
//        Row row = null;
//        ArrayList<Entry> list = null;
//        String cellData = null;
//        String filePath = "./data.xlsx";
//        //	入口名称	网址	简介	展示/折叠	预置添加
//        wb = ExcelReader.readExcel(filePath);
//
//        String name = "";
//
//        System.out.println("-------------------------解析Excel---------------------------");
//
//        ArrayList<String> titles = new ArrayList<>();
//
//        ArrayList<SubEntry> subEntries = new ArrayList<>();
//        if(wb != null){
//            //用来存放表中数据
//            //拿到最后一个
//            sheet = wb.getSheetAt(4);
//
//            int weight = 1;
//
//            for (int i = 1; i<ROW_SIZE; i++) {
//
//                SubEntry subEntry = new SubEntry();
//                row = sheet.getRow(i);
//
//                if(row !=null){
//                    for (int j=0;j<COLUMN_SIZE;j++){
//                        cellData = (String) ExcelReader.getCellFormatValue(row.getCell(j));
//                        if (j == 0) {
//                            if ("".equals(cellData)) {
//                                cellData = name;
//                            } else {
//                                name = cellData;
//                                weight = 1;
//                                titles.add(name);
//                                entryId++;
//                            }
//                        }
//
//                        switch (j) {
//                            case 0:{
//                                subEntry.parentId = entryId;
//                            } break;
//                            case 1:{
//                                subEntry.name = cellData;
//                            } break;
//                            case 2:{
//                                subEntry.href = cellData;
//                            } break;
//                            case 3:{
//                                subEntry.description = cellData;
//                            } break;
//                            case 4:{
//
//                            } break;
//                            case 5:{
//                                subEntry.subscribed = !"".equals(cellData);
//                            } break;
//                        }
//                    }
//                }else{
//                    break;
//                }
//
//                subEntry.id = -1;
//                subEntry.weight = weight++;
//                subEntry.type = 1;
//                subEntry.logo = "";
//                subEntry.updateTime = 0L;
//
//                subEntries.add(subEntry);
//            }
//        }
//
//        System.out.println("-------------------------数据对比修改---------------------------");
//
//        String sourceJsonStr = "{\n" +
//                "  \"code\": 200,\n" +
//                "  \"msg\": \"\",\n" +
//                "  \"data\": {\n" +
//                "    \"data\": [\n" +
//                "      {\n" +
//                "        \"id\": 1,\n" +
//                "        \"name\": \"常用\",\n" +
//                "        \"weight\": 1,\n" +
//                "        \"sides\": [\n" +
//                "          {\n" +
//                "            \"id\": 2,\n" +
//                "            \"name\": \"书签\",\n" +
//                "            \"description\": \"浏览器书签功能快捷入口\",\n" +
//                "            \"weight\": 1,\n" +
//                "            \"type\": 2,\n" +
//                "            \"href\": \"cqttech.home.nav.bookmark\",\n" +
//                "            \"logo\": \"/storage/user/20210825/bookmark.png\",\n" +
//                "            \"subscribed\": true,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 3,\n" +
//                "            \"name\": \"历史记录\",\n" +
//                "            \"description\": \"浏览器历史记录功能快捷入口\",\n" +
//                "            \"weight\": 2,\n" +
//                "            \"type\": 2,\n" +
//                "            \"href\": \"cqttech.home.nav.history\",\n" +
//                "            \"logo\": \"/storage/user/20210825/history.png\",\n" +
//                "            \"subscribed\": true,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 6,\n" +
//                "            \"name\": \"百度\",\n" +
//                "            \"description\": \"常用搜索引擎网站\",\n" +
//                "            \"weight\": 3,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.baidu.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/baidu.png\",\n" +
//                "            \"subscribed\": true,\n" +
//                "            \"updateTime\": 0\n" +
//                "          }\n" +
//                "        ]\n" +
//                "      },\n" +
//                "      {\n" +
//                "        \"id\": 2,\n" +
//                "        \"name\": \"看视频\",\n" +
//                "        \"weight\": 2,\n" +
//                "        \"sides\": [\n" +
//                "          {\n" +
//                "            \"id\": 1,\n" +
//                "            \"name\": \"腾讯视频\",\n" +
//                "            \"description\": \"海量高清视频在线观看\",\n" +
//                "            \"weight\": 1,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.v.qq.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/tencent_video.png\",\n" +
//                "            \"subscribed\": true,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 8,\n" +
//                "            \"name\": \"抖音\",\n" +
//                "            \"description\": \"记录美好生活\",\n" +
//                "            \"weight\": 8,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://douyin.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/douyin.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 9,\n" +
//                "            \"name\": \"爱奇艺\",\n" +
//                "            \"description\": \"全网好剧热综看不停\",\n" +
//                "            \"weight\": 3,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.iqiyi.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/iqy.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 10,\n" +
//                "            \"name\": \"优酷视频\",\n" +
//                "            \"description\": \"这世界很酷\",\n" +
//                "            \"weight\": 4,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://youku.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/youku_video.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 11,\n" +
//                "            \"name\": \"芒果TV\",\n" +
//                "            \"description\": \"天生青春\",\n" +
//                "            \"weight\": 5,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.mgtv.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/mango_tv.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 12,\n" +
//                "            \"name\": \"快手\",\n" +
//                "            \"description\": \"记录世界记录你\",\n" +
//                "            \"weight\": 6,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.kuaishou.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/kuaishou.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          }\n" +
//                "        ]\n" +
//                "      },\n" +
//                "      {\n" +
//                "        \"id\": 3,\n" +
//                "        \"name\": \"冲浪\",\n" +
//                "        \"weight\": 3,\n" +
//                "        \"sides\": [\n" +
//                "          {\n" +
//                "            \"id\": 13,\n" +
//                "            \"name\": \"微博\",\n" +
//                "            \"description\": \"随时随地发现新鲜事\",\n" +
//                "            \"weight\": 1,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.weibo.cn/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/sina_blog.png\",\n" +
//                "            \"subscribed\": true,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 7,\n" +
//                "            \"name\": \"知乎\",\n" +
//                "            \"description\": \"有问题，上知乎\",\n" +
//                "            \"weight\": 2,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://zhihu.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/zhihu.png\",\n" +
//                "            \"subscribed\": true,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 14,\n" +
//                "            \"name\": \"Bilibili\",\n" +
//                "            \"description\": \"正版动画番剧连载\",\n" +
//                "            \"weight\": 3,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.bilibili.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/bilibili.png\",\n" +
//                "            \"subscribed\": true,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 15,\n" +
//                "            \"name\": \"小红书\",\n" +
//                "            \"description\": \"美好生活分享社区\",\n" +
//                "            \"weight\": 4,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://xiaohongshu.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/xiaohongshu.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 16,\n" +
//                "            \"name\": \"豆瓣\",\n" +
//                "            \"description\": \"电影、读书、音乐、同城\",\n" +
//                "            \"weight\": 5,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://accounts.douban.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/douban.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 17,\n" +
//                "            \"name\": \"今日头条\",\n" +
//                "            \"description\": \"看见更大的世界\",\n" +
//                "            \"weight\": 6,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.toutiao.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/toutiao.png\",\n" +
//                "            \"subscribed\": true,\n" +
//                "            \"updateTime\": 0\n" +
//                "          }\n" +
//                "        ]\n" +
//                "      },\n" +
//                "      {\n" +
//                "        \"id\": 4,\n" +
//                "        \"name\": \"购物\",\n" +
//                "        \"weight\": 4,\n" +
//                "        \"sides\": [\n" +
//                "          {\n" +
//                "            \"id\": 4,\n" +
//                "            \"name\": \"淘宝\",\n" +
//                "            \"description\": \"万千好物淘不停\",\n" +
//                "            \"weight\": 1,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://main.m.taobao.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/taobao.png\",\n" +
//                "            \"subscribed\": true,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 5,\n" +
//                "            \"name\": \"京东\",\n" +
//                "            \"description\": \"多快好省，只为品质生活\",\n" +
//                "            \"weight\": 2,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.jd.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/jd.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 18,\n" +
//                "            \"name\": \"拼多多\",\n" +
//                "            \"description\": \"新电商开创者\",\n" +
//                "            \"weight\": 3,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.pinduoduo.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/pdd.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 19,\n" +
//                "            \"name\": \"唯品会\",\n" +
//                "            \"description\": \"品牌特卖，就是超值！\",\n" +
//                "            \"weight\": 4,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.vip.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/weipinhui.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 20,\n" +
//                "            \"name\": \"当当网\",\n" +
//                "            \"description\": \"海量图书，正品低价\",\n" +
//                "            \"weight\": 5,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"http://book.dangdang.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/dangdangwang.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 21,\n" +
//                "            \"name\": \"苏宁易购\",\n" +
//                "            \"description\": \"综合网上购物平台\",\n" +
//                "            \"weight\": 6,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.suning.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/suning.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          }\n" +
//                "        ]\n" +
//                "      },\n" +
//                "      {\n" +
//                "        \"id\": 5,\n" +
//                "        \"name\": \"生活服务\",\n" +
//                "        \"weight\": 8,\n" +
//                "        \"sides\": [\n" +
//                "          {\n" +
//                "            \"id\": 22,\n" +
//                "            \"name\": \"QQ音乐\",\n" +
//                "            \"description\": \"千万正版音乐，海量无损曲库\",\n" +
//                "            \"weight\": 1,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://i.y.qq.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/qq_music.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 23,\n" +
//                "            \"name\": \"美团\",\n" +
//                "            \"description\": \"吃喝玩乐全都有\",\n" +
//                "            \"weight\": 2,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://i.meituan.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/meituan.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 24,\n" +
//                "            \"name\": \"百度地图\",\n" +
//                "            \"description\": \"全国地图，智慧交通\",\n" +
//                "            \"weight\": 3,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://map.baidu.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/baidu_map.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 25,\n" +
//                "            \"name\": \"携程\",\n" +
//                "            \"description\": \"一站订酒店、机票、门票\",\n" +
//                "            \"weight\": 4,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.ctrip.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/xiecheng.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 26,\n" +
//                "            \"name\": \"中国天气网\",\n" +
//                "            \"description\": \"专业天气预报、气象服务\",\n" +
//                "            \"weight\": 5,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"http://weather.com.cn/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/china_wearher.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 27,\n" +
//                "            \"name\": \"马蜂窝\",\n" +
//                "            \"description\": \"旅游社交分享网站\",\n" +
//                "            \"weight\": 6,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.mafengwo.cn/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/mafengwo.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          }\n" +
//                "        ]\n" +
//                "      },\n" +
//                "      {\n" +
//                "        \"id\": 6,\n" +
//                "        \"name\": \"学习社区\",\n" +
//                "        \"weight\": 6,\n" +
//                "        \"sides\": [\n" +
//                "          {\n" +
//                "            \"id\": 28,\n" +
//                "            \"name\": \"微信读书\",\n" +
//                "            \"description\": \"正版书籍小说免费阅读\",\n" +
//                "            \"weight\": 1,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://weread.qq.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/wechat_reader.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 29,\n" +
//                "            \"name\": \"网易云阅读\",\n" +
//                "            \"description\": \"海量新闻资讯图书小说\",\n" +
//                "            \"weight\": 2,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://m.yuedu.163.com/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/wangyiyun_reader.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          },\n" +
//                "          {\n" +
//                "            \"id\": 30,\n" +
//                "            \"name\": \"中国知网\",\n" +
//                "            \"description\": \"中国知识基础设施工程\",\n" +
//                "            \"weight\": 3,\n" +
//                "            \"type\": 1,\n" +
//                "            \"href\": \"https://i.cnki.net/\",\n" +
//                "            \"logo\": \"/storage/user/20210825/china_zhiwang.png\",\n" +
//                "            \"subscribed\": false,\n" +
//                "            \"updateTime\": 0\n" +
//                "          }\n" +
//                "        ]\n" +
//                "      }\n" +
//                "    ]\n" +
//                "  }\n" +
//                "}";
//
//
//        Gson sourceGson = new Gson();
//        Type type = new TypeToken<Result<Data>>(){}.getType();
//        Result<Data> result1 = sourceGson.fromJson(sourceJsonStr, type);
//
//        System.out.println("-------------------------生成Json数据---------------------------");
//
//        for (SubEntry subEntry : subEntries) {
//
//            for (Entry datum : result1.data.data) {
//                for (SubEntryInner side : datum.sides) {
//                    if (side.href.equals(subEntry.href)) {
//                        subEntry.logo = side.logo;
//                        subEntry.id = side.id;
//                    }
//                }
//            }
//        }
//
//        Data data = new Data();
//        data.data = new ArrayList<>();
//        for (int i = 1; i <= titles.size(); i++) {
//            Entry entry = new Entry();
//            entry.name = titles.get(i-1);
//            entry.id = i;
//            entry.weight = i;
//            entry.sides = new ArrayList<>();
//            data.data.add(entry);
//        }
//
//        for (SubEntry subEntry : subEntries) {
//            for (Entry entry : data.data) {
//                if (subEntry.parentId == entry.id) {
//                    entry.sides.add(subEntry.getSunEntryInner());
//                }
//            }
//        }
//
//
//        Result<Data> result = new Result<>();
//        result.code = 200;
//        result.msg = "";
//        result.data = data;
//
//        Gson gson = new Gson();
//        String json = gson.toJson(result);
//        System.out.println(json);
//
//
//    }

//    public static void main(String[] args){
//        File file = new File("./DCBrowser.log.20211129");
//        System.out.println(file.exists());
//
//        ArrayList<Log> logs = new ArrayList<>();
//
//        Gson gson = new Gson();
//
//        try {
//            BufferedReader reader = new BufferedReader(new FileReader(file));
//            String line = reader.readLine();
//            while (line != null) {
//                System.out.println(line);
//                Log log = gson.fromJson(line, Log.class);
//                logs.add(log);
//                line = reader.readLine();
//            }
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        System.out.println(logs.size());
//
//
//        String[] header = {"timestamp", "version", "client_ip","ctype","unionid","custom_data","os_version","arch","os_type","pcid",
//                "sub_module","event_id","c_timestamp","business","appid"};
//        ExcelWirter.export(logs, header);
//    }
}
